<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">营销名称<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<input type="text" id="name" name="name" lay-verify="required" autocomplete="off" placeholder="营销名称：" class="layui-input" />
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">营销标题<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<input type="text" id="title" name="title" lay-verify="required" autocomplete="off" placeholder="营销标题：" class="layui-input" />
								</div>
							</div>
							<!--<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">店铺名称</label>
									<div class="layui-input-inline">
										<input type="text" name="shopname" placeholder="请输入店铺名称" autocomplete="off" class="layui-input" lay-verify="required">
									</div> 
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">店铺编号</label>
									<div class="layui-input-inline">
										<input type="text" name="shopid" placeholder="请输入店铺编号" autocomplete="off" class="layui-input">
									</div>
									<div class="layui-form-mid layui-word-aux"><a href="Javascript:;" onclick="searchdata('shopid')">选择</a></div>
								</div>
							</div>-->
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">专属等级</label>
									<div class="layui-input-inline">
										<select name="level" class="site_union">
										</select>
									</div>
								</div> 
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">图标<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" onclick="choose(1)">上传图标</button><span style="color:red"><p>建议上传340*220大小图片</p></span>
									<ul class="show_img_ul" id="icon_url"></ul>
								</div>
							</div>
							
							
							
							<div class="layui-form-item">
								<label class="layui-form-label">主图<span style="color:red">*</span></label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" onclick="choose(2)">上传图片</button><span style="color:red"><p>建议上传750*375大小图片</p></span>
									<ul class="show_img_ul" id="img_url"></ul>
								</div>
							</div>

							<div class="layui-form-item"><label class="layui-form-label">活动主题色<span style="color:red">*</span></label>
								<div class="layui-input-inline" style="width: 41.5%;">
									<input type="text" value="" placeholder="活动主题色" class="layui-input" id="color" name='color'>
								</div>
								<div class="layui-inline" style="left: -11px;">
									<div id="test-form"></div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">内容</label>
								<div class="layui-input-block">
									<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="demo_editor"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">开始时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="s_time" class="layui-input" id="s_time" autocomplete="off" placeholder="开始时间：">
								</div>
								<label class="layui-form-label">结束时间：</label>
								<div class="layui-input-inline">
									<input type="text" name="e_time" class="layui-input" id="e_time" autocomplete="off" placeholder="开始时间：">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">规则</label>
								<div class="layui-input-block">
									<textarea type="text" id="rule" name="rule" autocomplete="off" placeholder="规则：" class="layui-textarea"></textarea>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<input type="text" id="remark" name="remark" autocomplete="off" placeholder="备注：" class="layui-input" />
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">排序</label>
								<div class="layui-input-inline">
									<input type="text" id="remark" name="oid" autocomplete="off" placeholder="排序" class="layui-input" />
								</div>
							</div>

						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'upload', 'colorpicker'], function() {
				var $ = layui.$,
					admin = layui.admin,
					upload = layui.upload,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					layedit = layui.layedit,
					colorpicker = layui.colorpicker;
				form = layui.form;

				var maplist = JSON.parse(localStorage.getItem('lsmap')),
					img_arr1 = [];
					img_arr2 = [];
				
				site_union_show("option")
				layedit.set({
					//暴露layupload参数设置接口 --详细查看layupload参数说明
					uploadImage: {
						url: server.upimg,
						accept: 'image',
						acceptMime: 'image/*',
						exts: 'jpg|png|gif|bmp|jpeg',
						size: 1024 * 10,
						data: {},
						done: function(data) {
							console.log(data);
						}
					},
					uploadVideo: {
						url: server.upimg,
						accept: 'video',
						acceptMime: 'video/*',
						exts: 'mp4|flv|avi|rm|rmvb',
						size: 1024 * 10 * 2,
						done: function(data) {
							// console.log(data);
						}
					},
					uploadFiles: {
						url: server.upimg,
						accept: 'file',
						acceptMime: 'file/*',
						size: '20480',
						autoInsert: true, //自动插入编辑器设置
						done: function(data) {
							// console.log(data);
						}
					},
					//右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
					//传递参数：
					//图片： imgpath --图片路径
					//视频： filepath --视频路径 imgpath --封面路径
					//附件： filepath --附件路径
					calldel: {
						url: server.upimg,
						done: function(data) {
							// console.log(data);
						}
					},
					rightBtn: {
						type: "layBtn", //default|layBtn|custom  浏览器默认/layedit右键面板/自定义菜单 default和layBtn无需配置customEvent
						customEvent: function(targetName, event) {
							//根据tagName分类型设置
							switch(targetName) {
								case "img":
									alert("this is img");
									break;
								default:
									alert("hello world");
									break;
							};
							//或者直接统一设定
							//alert("all in one");
						}
					},
					//测试参数
					backDelImg: true, //开发者模式 --默认为false
					devmode: true, //是否自动同步到textarea
					autoSync: true, //内容改变监听事件
					onchange: function(content) {
						// console.log(content);
					}, //插入代码设置 --hide:false 等同于不配置codeConfig
					codeConfig: {
						hide: true, //是否隐藏编码语言选择框
						default: 'javascript', //hide为true时的默认语言格式
						encode: true,
						class: 'layui-code' //默认样式
					},
					facePath: 'http://knifez.gitee.io/kz.layedit/Content/Layui-KnifeZ/',
					devmode: true,
					videoAttr: ' preload="none"',
					tool: [
						'html', 'undo', 'redo', 'code', 'strong', 'italic', 'underline', 'del', 'addhr', '|', 'removeformat',
						'fontFomatt', 'fontfamily', 'fontSize', 'fontBackColor', 'colorpicker', 'face', '|', 'left', 'center',
						'right', '|', 'link', 'unlink', 'images', 'video', 'attachment', 'anchors', '|', 'table',
						'customlink', 'fullScreen', 'preview'
					],
					height: '500px'
				});
				var indexbuild = layedit.build('demo_editor'); //建立编辑器

				if(_data.id) {
					initdata();
				}

				//日期时间选择器
				laydate.render({
					elem: '#s_time',
					type: 'date'
				});
				//日期时间选择器
				laydate.render({
					elem: '#e_time',
					type: 'date'
				});
				//表单赋值
				colorpicker.render({
					elem: '#test-form',
					done: function(color) {
						$('#color').val(color);
					}
				});


				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.content = layedit.getContent(indexbuild);
					_data.icon_url = img_arr1.join(',');
					_data.img_url = img_arr2.join(',');
					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.market_edit);
						} else {
							delete _data.id
							submitdata(server.market_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				}
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				
				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '1':
								createli(data, 'icon_url', type)
								break;
							case '2':
								createli(data, 'img_url', type)
								break;
							default:
								break;
						}
					}
				}

				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '1':
								img_arr1.splice(i, 1)
								break;
							case '2':
								img_arr2.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});

				}

				function createli(data, dom, type) {
					// console.log(data);
					var lihtml = '';
					switch (type) {
						case '1':
							if (data.indexOf(',') == -1) {
								img_arr1.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr1.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr1.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr1[i] + ' >' +
									'<p onclick="delimg(' + i + ',1,this)">删除</p>' +
									'</li>'
							}
							break;
						case '2':
							if (data.indexOf(',') == -1) {
								img_arr2.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr2.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr2.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr2[i] + ' >' +
									'<p onclick="delimg(' + i + ',2,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}
				window.searchdata = function(type) {
					switch(type) {
						case 'shopid':
							layer.open({
								type: 2,
								title: '选择',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: 'choose_shop.html',
								end: function() {},
								success: function() {}
							});
							break;
					}
				}
		
				function initdata() {
					$.get(server.market_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.market
								data.data.icon_url ? createli(data.data.icon_url, 'icon_url', '1') : '';
								data.data.img_url ? createli(data.data.img_url, 'img_url', '2') : '';
								form.val("test_detail", data.data);
								layedit.setContent(indexbuild, data.data.content); //填充富文本
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
			});
		</script>
	</body>

</html>